package com.bq.gametrade.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bq.gametrade.R;
import com.bq.gametrade.bean.TransferBillDetails;
import com.bq.gametrade.bean.UserInfoDetails;
import com.bq.gametrade.utils.FormatUtil;

import java.util.ArrayList;

/**
 * Created by Feel on 2016/12/20.
 */

public class TransferBilAdapter extends BaseAdapter {

    private ArrayList<TransferBillDetails> list;
    private Context context;
    private UserInfoDetails userInfoDetails;

    public TransferBilAdapter(Context context, ArrayList<TransferBillDetails> items,UserInfoDetails userInfoDetails) {
        this.context = context;
        this.list = items;
        this.userInfoDetails = userInfoDetails;
    }

    public void setData(ArrayList<TransferBillDetails> items) {
        this.list = items;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.listview_item_transferbill, null);
            viewHolder.tvTransferDate = (TextView) convertView.findViewById(R.id.ctime);
            viewHolder.tvTransferWay = (TextView) convertView.findViewById(R.id.tv_transferWay);
            viewHolder.tvTransferAccount = (TextView) convertView.findViewById(R.id.tv_transferAccount);
            viewHolder.tvTransferCount = (TextView) convertView.findViewById(R.id.tv_transferCount);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        TransferBillDetails details = list.get(position);
        viewHolder.tvTransferDate.setText(details.ctime);
        /***
         * 1:转RMB 本账户→其他账户
         * 2:转鱼券 本账户→其他账户
         *
         * 3:转RMB 其他账户→本账户
         * 4:转鱼券 其他账户→本账户
         */
        if (details.transfer_user.equals(userInfoDetails.account)) {
            if (details.type.equals("0")) {
                viewHolder.tvTransferWay.setText("鱼券");
                viewHolder.tvTransferWay.setTextColor(context.getResources().getColor(R.color.blue_500));
                viewHolder.tvTransferAccount.setText("我 —" + details.revice_user);
                viewHolder.tvTransferCount.setText("-" + details.num + "个");
            } else {
                viewHolder.tvTransferWay.setText("余额");
                viewHolder.tvTransferAccount.setText("我 —" + details.revice_user);
                viewHolder.tvTransferCount.setText("-" + FormatUtil.valueFormatWithTwo(details.num.replace(",","")) + "元");
            }

        }else{
            if (details.type.equals("1")) {
                viewHolder.tvTransferWay.setText("余额");
                viewHolder.tvTransferAccount.setText(details.transfer_user + "— 我");
                viewHolder.tvTransferCount.setText("+" + FormatUtil.valueFormatWithTwo(details.num.replace(",","")) + "元");

            } else {
                viewHolder.tvTransferWay.setText("鱼券");
                viewHolder.tvTransferWay.setTextColor(context.getResources().getColor(R.color.blue_500));
                viewHolder.tvTransferAccount.setText(details.transfer_user + "— 我");
                viewHolder.tvTransferCount.setText("+" + details.num.replace(",","") + "个");

            }
        }

        return convertView;
    }

    class ViewHolder {
        TextView tvTransferDate;
        TextView tvTransferWay;
        TextView tvTransferAccount;
        TextView tvTransferCount;
    }
}
